<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: sun
  Date: 2020/11/24
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>留言</title>
</head>
<style>
    #reply{
        width: 570px;
        height: 300px;
        left:500px;
        top:250px;

    }
    #ti{
        position: absolute;
        left: 650px;
        top:436px;
    }

    #modalaa{
        width:500px;
        height: 350px;
    }
</style>
<script type="text/javascript">
        function setShowLength(obj, maxlength, id) {
            var rem = maxlength - obj.value.length;
            var wid = id;
            if (rem < 0){
                rem = 0;
            }
            document.getElementById(wid).innerHTML = "还可以输入" + rem + "字数";
        }
        
        //批量删除
    function deleteButton() {
        //判断至少写了一项
        var checkedNum=$("input[name='subcheck']:checked").length;
        if(checkedNum==0){
            alert("请至少选择一项！！");
            return false;
        }
        if(confirm("确定删除所选项目？")){
            var checkedList=new Array();
            $("input[name='subcheck']:checked").each(function () {
                checkedList.push($(this).val());
            });
            $.ajax({
                type :"POST",
                url : "/remarks/delete",
                data : {"remarks":checkedList.toString()},
                dataType : "html",
                success : function (data) {
                    // $("[name='checkbox']:checkbox").attr("checked",false);
                    $(":checkbox").prop("checked",false)
                    location.reload();//页面刷新
                },
                error:function (data) {
                    art.dialog.tips("删除失败！");
                }
            })
        }
    }

    function guanli() {
        $("#table td:nth-child(1)").show()
        $("#table th:nth-child(1)").show();
        $("#deleteButton").show();
        $("#selectAll").show();
        $("#ends").show();
        $("#guanli").hide();
    }

    //全选
    function selectAll() {
            $(":checkbox").prop("checked",true);//所有选择框都选中
            $("#selectAllNo").show()

    }
    //取消全选
    function selectAllNo() {
        $(":checkbox").prop("checked",false);
        $("#selectAllNo").hide()
    }
    //完成
    function ends() {
         //页面刷新
        location.reload();
    }



</script>
<body>
<jsp:include page="hade.jsp"/>
<div class="container">
    <p>勾正管理系统--->留言管理</p>
    <a href="/remarks/toRemarks"><button class="btn btn-primary">留个言吧</button></a>
    <button type="button" id="guanli" class="btn btn-info" onclick="guanli()">管理</button>
    <button type="button" id="ends" class="btn btn-info"  style="display: none;" onclick="ends()">完成</button>
    <a id="selectAll" onclick="selectAll()" style="display: none" class="btn btn-primary">全选</a>
    <a id="selectAllNo" onclick="selectAllNo()" style="display: none" class="btn btn-primary">取消全选</a>
    <button class="btn btn-danger" id="deleteButton" onclick="deleteButton()" style="display: none">全部删除</button>
<form action="/remarks/findAllRemarks" method="post">
</form>
<table class="table table-hover" id="table">
    <thead>
    <tr>
        <%--<th><input type="checkbox" id="SelectAll" onclick="selectAll();"></th>--%>
        <th style="display: none">v</th>
        <th>姓名</th>
        <th>留言</th>
    </tr>
    </thead>
<tbody>
<c:forEach items="${remarks}" var="remarks">
    <tr>
        <td width="8%" height="13" align="center" style="display: none">
            <input type="checkbox" value="${remarks.rid}" name="subcheck" />
        </td>
        <td>${remarks.stuName}</td>
        <td>${remarks.rDis}</td>
    </tr>
    <%--<p>${msg}</p>--%>
</c:forEach>
</tbody>

</table>


</div>

</body>
</html>
